<template>
   <el-card>
      <!-- 教学点管理 -->
      <bread-crumb slot="header">
        <template slot="title">教学点管理</template>
      </bread-crumb>
      <div class="Contaner">
          <div class="QueryBtn">
            <el-select v-model="value" placeholder="请选择" style=" width: 170px;">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-input v-model="input" placeholder="请输入内容" style="width: 210px;margin-left: 20px;"></el-input>
              <el-button @click="teachingSchool('Query')" style="margin-left: 20px; height: 25px; line-height: 3px;" type="primary">查询</el-button>
              <el-button @click="exportBouncedsss = true" style="margin-left: 20px; height: 25px; line-height: 3px;" type="text">高级搜索</el-button>
          </div>
        <el-tabs type="border-card">
          <el-tab-pane label="教学点查询">
             <!-- <el-button @click="exportBounced = true" type="primary" style="margin-bottom: 16px; margin-top: 15px;">导出数据</el-button> -->
              <el-table :header-cell-style="{ background: '#eee', color: '#606266' }" :data="tableData"  max-height="450" style="width: 100%">
                <el-table-column label="教学点名称" width="340%">
                  <template slot-scope="{row}">
                    <el-button
                    @click="teachingInfo(row)"
                      type="text"
                      size="small">
                      {{row.name}}
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="servicesName" label="所属机构" ></el-table-column>
                <el-table-column prop="address" label="教学点位置" ></el-table-column>
                <el-table-column prop="contactsName" label="联系人姓名" ></el-table-column>
                <el-table-column prop="contactsTel" label="联系人手机号" ></el-table-column>
                <el-table-column label="办件类型" >
                  <template slot-scope="{row}">
                    <p>
                      {{row.reviewType == 'add' ? '新增' : '注销'}}
                    </p>
                  </template>
                </el-table-column>
              </el-table>
              <!-- 分页 -->
                <el-row
                  type="flex"
                  align="middle"
                  justify="end"
                  style="margin-top: 20px"
                >
                  <el-col :span="8">
                    <el-pagination
                      background
                      layout="total, prev, pager, next, sizes"
                      :total="page.total"
                      :page-sizes="[7, 10, 20, 50, 100]"
                      :page-size="page.pageSize"
                      @current-change="changePage"
                      @size-change="handleSizeChange"
                      :current-page.sync="page.currentPage"
                    ></el-pagination>
                  </el-col>
                </el-row>
          </el-tab-pane>
          <el-tab-pane label="教学点审批">
            <div class="Selectionsss">
              <div class="left_btn">
               <el-button plain @click="teachingSchool('全部')">全部</el-button>
               <el-button plain @click="teachingSchool('待审批')">待审批</el-button>
               <el-button plain @click="teachingSchool('已通过')">已通过</el-button>
               <el-button plain @click="teachingSchool('未通过')">未通过</el-button>
              </div>
              <div class="right_shenhe" v-show="true">
                <el-button type="success" @click="doPointReview">批量通过</el-button>
                <el-button type="danger" @click="stipo">批量不通过</el-button>
              </div>
            </div>
              <el-table :header-cell-style="{ background: '#eee', color: '#606266' }" :data="tableData"  max-height="450" style="width: 100%"
              tooltip-effect="dark"
              @selection-change="handleSelectionChange"
              >
              <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="教学点名称" width="170%">
                  <template slot-scope="{row}">
                    <el-button
                      @click="teachingInfo(row)"
                      type="text"
                      size="small">
                      {{row.name}}
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="servicesName" label="所属机构" ></el-table-column>
                <el-table-column prop="address" label="教学点位置" ></el-table-column>
                <el-table-column prop="contactsName" label="联系人姓名" ></el-table-column>
                <el-table-column prop="contactsTel" label="联系人手机号" ></el-table-column>
                <el-table-column label="办件类型" >
                  <template slot-scope="{row}">
                    <p>
                      {{row.reviewType == 'add' ? '新增' : '注销'}}
                    </p>
                  </template>
                </el-table-column>
                <el-table-column prop="licencessss" label="审批状态" >
                  <template slot-scope="{row}">
                    <p>
                      {{row.reviewStatus === 0 ? '未通过' : row.reviewStatus === 1 ? '待审核' : '已通过'}}
                    </p>
                  </template>
                </el-table-column>
                <el-table-column show-overflow-tooltip label="申报时间" >
                  <template slot-scope="{row}">
                    <p>
                      <!-- {{row.reviewDate}} -->
                      {{formatTime(row.reviewDate * 1000)}}
                    </p>
                  </template>
                </el-table-column>
              </el-table>
              <!-- 分页 -->
                <el-row
                  type="flex"
                  align="middle"
                  justify="end"
                  style="margin-top: 20px"
                >
                  <el-col :span="8">
                    <el-pagination
                      background
                      layout="total, prev, pager, next, sizes"
                      :total="page.total"
                      :page-sizes="[7, 10, 20, 50, 100]"
                      :page-size="page.pageSize"
                      @current-change="changePage"
                      @size-change="handleSizeChange"
                      :current-page.sync="page.currentPage"
                    ></el-pagination>
                  </el-col>
                </el-row>
          </el-tab-pane>
        </el-tabs>
      </div>
      <!-- 导出弹框 -->
      <el-dialog title="导出数据" width="500px" :visible.sync="exportBounced">
        <div class="ExportBtn">
          <el-button type="primary">导出当前页</el-button>
          <el-button style="margin-left: 60px" type="primary"
            >导出全部数据（搜索后）</el-button
          >
        </div>
      </el-dialog>
      <!-- 高级搜索 -->
      <el-dialog title="高级搜索" width="700px" :visible.sync="exportBouncedsss">
        <div class="Top_seach">
          <p>时间筛选</p>
          <div class="blocksss">
            <span class="demonstration">申报时间：</span>
            <el-date-picker
              v-model="value1"
              type="datetime"
              placeholder="选择日期">
            </el-date-picker>
          </div>
          <p>组合搜索</p>
          <div class="tabelskc"><div class="left_name">教学点名称：</div><div class="shuru"><el-input v-model="teachingInfos.name" /></div></div>
          <div class="tabelskc"><div class="left_name">教学点位置：</div><div class="shuru"><el-input v-model="teachingInfos.address" /></div></div>
          <div class="tabelskc"><div class="left_name">联系人姓名：</div><div class="shuru"><el-input v-model="teachingInfos.contactsName" /></div></div>
          <div class="tabelskc"><div class="left_name">办件类型：</div><div class="shuru">
              <el-select v-model="teachingInfos.reviewType" placeholder="请选择" style="width: 100%;">
                <el-option
                  v-for="item in optionsskc"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </div></div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="exportBouncedsss = false">取 消</el-button>
          <el-button type="primary" @click="teachingSchool('高级搜索')">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 详细信息 -->
      <el-dialog title="详细信息" width="600px" :visible.sync="exportBouncedsssss">
        <div class="big_Info"><div>教学点名称：</div><div style="margin-left: 2px;">{{ teaching.name }}</div></div>
        <div class="big_Info"><div>教学点联系电话：</div><div style="margin-left: 2px;">{{ teaching.contactsTel }}</div></div>
        <div class="big_Info"><div>教学点地址：</div><div style="margin-left: 2px;">{{ teaching.address }}</div></div>
        <div class="big_Info"><div>教学点经纬度信息：</div><div style="margin-left: 2px;">暂无</div></div>
      </el-dialog>
   </el-card>
</template>

<script>
import { teachingSchool, doPointReview } from '@/api'
export default {
  data () {
    return {
      exportBouncedsssss: false,
      exportBounced: false,
      exportBouncedsss: false,
      teaching: {}, // 教学点详情信息
      optionsskc: [{
        value: null,
        label: '全部办件'
      }, {
        value: 'add',
        label: '新增办件'
      }, {
        value: 'del',
        label: '注销办件'
      }],
      options: [{
        value: 1,
        label: '教学点名称'
      }, {
        value: 2,
        label: '教学点地址'
      }, {
        value: 3,
        label: '联系人姓名'
      }, {
        value: 4,
        label: '所属机构'
      }],
      value: '',
      value1: '',
      input: '',
      multipleSelection: [],
      teachingInfos: {
        name: '', // 教学点名字
        address: '', // 教学点位置
        contactsName: '', // 联系人名字
        reviewType: '' // 板件类型
      },
      page: {
        // 分页数据
        total: 1000, // 总条数
        currentPage: 1, // 默认的页码 是第一个页  决定了当前页码是第几页
        pageSize: 9 // page-size的默认值是10条
      },
      tableData: [] // 表格数据
    }
  },
  created () {
    this.teachingSchool()
  },
  methods: {
    // 教学点详情
    teachingInfo (item) {
      this.exportBouncedsssss = true
      this.teaching = item
    },
    // 请求教学点列表数据
    async teachingSchool (type) {
      let data = {}
      switch (type) {
        case 'Query':
          data = {
            searchType: this.value,
            searchContent: this.input
          }
          break
        case '待审批':
          data = {
            type: 1
          }
          break
        case '已通过':
          data = {
            type: 2
          }
          break
        case '未通过':
          data = {
            type: 0
          }
          break
        case '高级搜索':
          data = this.teachingInfos
          this.value1 ? (data.time = new Date(this.value1).valueOf()) : console.log('')
          break
        case '批量不通过':
        // data =
          break
        default:
          data = {}
          break
      }
      const ser = await teachingSchool(data)
      console.log(ser)
      if (ser?.code === 200) {
        const { list, total } = ser?.data
        console.log('大数组的数据', list)
        this.tableData = list
        this.page.total = total
      }
      this.exportBouncedsss = false
    },
    // 批量同意
    async doPointReview () {
      const a = this.multipleSelection.map((item) => {
        return item.id
      })
      const data = {
        idList: a,
        reviewStatus: 2
      }
      const ser = await doPointReview(data)
      if (ser.code === 200) {
        this.$message.success(ser.msg)
        this.teachingSchool()
      }
    },
    // 批量拒绝
    stipo () {
      this.$prompt('请输入拒绝理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(async ({ value }) => {
        if (value === null || value === '') {
          this.$message({
            type: 'error',
            message: '请输入原因'
          })
          return false
        }
        const a = this.multipleSelection.map((item) => {
          return item.id
        })
        const data = {
          idList: a,
          reviewStatus: 0,
          reviewRemarks: value
        }
        const ser = await doPointReview(data)
        if (ser.code === 200) {
          this.$message.success(ser.msg)
          this.teachingSchool()
        }
      })
    },
    // 当选择项发生变化时会触发该事件
    handleSelectionChange (val) {
      console.log('我选择了')
      console.log(val)
      this.multipleSelection = val
    },
    // 格式化 毫秒级时间戳 1637338090875
    formatTime (item) {
      return this.$formatTime(item)
    }
  }
}
</script>

<style lang="less" scopde>
  .Selectionsss {
    padding-top: 10px;
    padding-bottom: 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .left_btn {

      .el-button+.el-button {
        margin-left: 0;
    }
      }
  }
  .big_Info {
    display: flex;
    padding: 0 24px 16px;
    color: rgba(0,0,0,.85);
  }
.Top_seach {
  .tabelskc {
    display: flex;
      margin-bottom: 24px;
    .shuru {
      width: 100%;
    }
    .left_name {
      width: 180px;
      height: 32px;
      text-align: right;
      line-height: 32px;
    }
  }
      .blocksss {
      padding: 0 0 0 75px;
      margin-bottom: 24px;
    }
  .category {
    padding: 0 0 0 20px;
    display: flex;
    align-items: center;
    margin-bottom: 24px;
    .checkboxs {
      width: 500px;
      display: flex;
      flex-wrap: wrap;
      .el-checkbox {
        margin-right: 15px;
      }
    }
  }
  p {
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 20px;
    color: #000000;
  }
}
  .ExportBtn {
    width: 80%;
    margin: 0px 40px 0px;
    padding-bottom: 40px;
  }
  .el-card__body {
    padding: 0 !important;

      .el-dialog {
    margin-bottom: 0 !important;
  }

  .el-dialog__body {
    padding: 30px 20px 0;
    border-top: 1px solid #e4e4e4;
  }
  }
  .Contaner {
    position: relative;
  }
  .QueryBtn {
    display: flex;
    align-items: center;
    width: 550px;
    height: 40px;
    position: absolute;
    top: 0;
    right: 30px;
    z-index: 1;
    .el-input__suffix {
      line-height: 50px;
    }
    input {
      height: 30px;
    }
  }
</style>
